using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Ruminate.Utils;

namespace Ruminate.GUI.Framework {

    public abstract class Renderer {

        public Texture2D ImageMap { get; set; }

        protected RuminateGUI GUI { get; set; }

        protected GraphicsDevice GraphicsDevice { get { return GUI.InstanceData.GraphicsDevice; } }

        protected Renderer(RuminateGUI gui, Texture2D imageMap) {

            GUI = gui;
            ImageMap = imageMap;
        }

        internal protected virtual Rectangle BuildSafeArea(Point size) { return Rectangle.Empty; }

        protected static void RenderStencilandOverlay(TextureBaker baker, Texture2D imageMap,
            Texture2D background, Texture2D stencil, Texture2D overlay, Point size) {

            //Setup
            var area = new Rectangle(0, 0, size.X, size.Y);

            //Tile the background across the 
            baker.SetState(RenderState.Tile);
            baker.Draw(background, Vector2.Zero, area, Color.White);

            //Fill in the background using the stencil
            baker.SetState(RenderState.Stencil);
            baker.Draw(stencil, area, area, Color.White);

            //Apply the overlay
            baker.SetState(RenderState.Fill);
            baker.Draw(overlay, area, area, Color.White);
        }        
    }
}
